#include "bsp_I2c.h"
#include "sys_Debug.h"

bsp_I2c::I2C_ret bsp_I2c::write(uint8_t Address, uint8_t *pData, int size)
{
    uint8_t buff = *pData;
    if (BSP_I2C_Write(i2c, Address, &buff, size, I2C_TIMEOUT) != BSP_OK)
    {
        SysError("I2C_ERROR\r\n");
        return I2C_ERROR;
    }
    else
        return I2C_OK;
}

bsp_I2c::I2C_ret bsp_I2c::write(uint8_t Address, uint8_t pData)
{
    if (BSP_I2C_Write(i2c, Address, &pData, 1, I2C_TIMEOUT) != BSP_OK)
    {
        SysError("I2C_ERROR\r\n");
        return I2C_ERROR;
    }
    else
        return I2C_OK;
}

bsp_I2c::I2C_ret bsp_I2c::read(uint8_t Address, uint8_t Reg, uint8_t *pData, int size)
{
    if (BSP_I2C_Read(i2c, Address, Reg, pData, size, I2C_TIMEOUT) != BSP_OK)
    {
        SysError("I2C_ERROR\r\n");
        return I2C_ERROR;
    }
    else
        return I2C_OK;
}
